﻿using System.Windows;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using WP8_PPS.Resources;
using Microsoft.Phone.Shell;

namespace WP8_PPS.Views
{
    public partial class SingleSurveyEntryPage : PhoneApplicationPage
    {
        #region Constructor
        public SingleSurveyEntryPage()
        {
            InitializeComponent();

            // Set up Data Binding to View Model
            this.DataContext = App.ViewModel_SingleSurveyEntry;
        }
        #endregion

        #region Navigation Overrides
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            SystemTray.ProgressIndicator = new ProgressIndicator();

            // Asking for consent to access location
            // If does not contain previous consent then ask
            if (!(IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent") && (bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true))
            {
                // Localizing the Message box for Location Consent
                MessageBoxResult result = MessageBox.Show(AppResources.LocationConsentMessage,
                                                          AppResources.LocationConsentLabel,
                                                          MessageBoxButton.OKCancel);

                // Store users answer for later
                if (result == MessageBoxResult.OK)
                {
                    IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
                }
                else
                {
                    IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
                }

                // Save application settings
                IsolatedStorageSettings.ApplicationSettings.Save();
            }
        }
        #endregion
    }
}